package com.hxd.otc.module.wallet.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hxd.otc.R;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.module.wallet.bean.WalletCurrencyBean;
import com.hxd.otc.utils.StringUtil;
import com.hxd.otc.utils.UIUtils;
import com.hxd.otc.widget.BlocksToast;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/5 18:03
 * 描  述 :  ${全部订单页面}
 */
public class OtcAssestAdapter extends BaseQuickAdapter<WalletCurrencyBean, BaseViewHolder> {

    private int pos;

    public void setPos(int pos) {
        this.pos = pos;
    }

    public OtcAssestAdapter() {
        super(R.layout.item_wallet_currency, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, final WalletCurrencyBean item) {

        helper.setText(R.id.tv_coin_logo, item.getName());

        helper.setText(R.id.tv_available_balance, StringUtil.handleZero(item.volume + ""));
        helper.setText(R.id.tv_freeze_balance, StringUtil.handleZero(item.otcLockVolume + ""));
        if ((item.otcAdvertVolume + item.otcLockVolume) == 0) {
            helper.setText(R.id.tv_freeze_balance, "0");
        } else {
            helper.setText(R.id.tv_freeze_balance, StringUtil.handleZero(item.otcAdvertVolume + item.otcLockVolume + ""));
        }
        switch (pos) {
            case 0:
                helper.setText(R.id.tv_enter, R.string.wallet_into);
                helper.setGone(R.id.tv_out, false);

                if (UserHelper.isSilver()) {
                    helper.setGone(R.id.tv_fee_reserve, true);
                    helper.setGone(R.id.tv_fee_reserve_lable, true);
                    if (item.bailVolume == 0) {
                        helper.setText(R.id.tv_fee_reserve, "0");
                    } else {
                        helper.setText(R.id.tv_fee_reserve, StringUtil.handleZero(item.bailVolume + ""));
                    }
                } else {
                    helper.setGone(R.id.tv_fee_reserve, false);
                    helper.setGone(R.id.tv_fee_reserve_lable, false);
                }

                break;
            case 1:
                helper.setGone(R.id.tv_out, true);
                helper.setText(R.id.tv_enter, R.string.wallet_recharge);
                helper.setText(R.id.tv_out, R.string.wallet_withdraw);
                helper.setGone(R.id.tv_fee_reserve, false);
                helper.setGone(R.id.tv_fee_reserve_lable, false);
                switch (item.tokenStatus) {
                    case 9:
                        helper.getView(R.id.tv_out).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.shape_wallet_currency_no_use));
                        helper.setTextColor(R.id.tv_out, UIUtils.getContext().getResources().getColor(R.color.colorWhite));

                        helper.getView(R.id.tv_enter).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.shape_wallet_currency_no_use));
                        helper.setTextColor(R.id.tv_enter, UIUtils.getContext().getResources().getColor(R.color.colorWhite));
                        break;
                    case 1:
                        helper.getView(R.id.tv_out).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.selector_wallet_btn_yellow));
                        helper.setTextColor(R.id.tv_out, UIUtils.getContext().getResources().getColor(R.color.color_text1));

                        helper.getView(R.id.tv_enter).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.selector_wallet_btn_black));
                        helper.setTextColor(R.id.tv_enter, UIUtils.getContext().getResources().getColor(R.color.colorWhite));
                        break;
                    case 2:
                        helper.getView(R.id.tv_out).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.shape_wallet_currency_no_use));
                        helper.setTextColor(R.id.tv_out, UIUtils.getContext().getResources().getColor(R.color.colorWhite));

                        helper.getView(R.id.tv_enter).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.selector_wallet_btn_black));
                        helper.setTextColor(R.id.tv_enter, UIUtils.getContext().getResources().getColor(R.color.colorWhite));
                        break;
                    case 3:
                        helper.getView(R.id.tv_out).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.selector_wallet_btn_yellow));
                        helper.setTextColor(R.id.tv_out, UIUtils.getContext().getResources().getColor(R.color.color_text1));

                        helper.getView(R.id.tv_enter).setBackgroundDrawable(UIUtils.getContext().getResources().getDrawable(R.drawable.shape_wallet_currency_no_use));
                        helper.setTextColor(R.id.tv_enter, UIUtils.getContext().getResources().getColor(R.color.colorWhite));
                        break;
                }
                break;
        }

        helper.getView(R.id.tv_out).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemListener != null) {
                    // // 充值提现状态  9：不可以充值提现 1 ：可以充值 可以提现 2：仅可以充值 3：仅可以提现
                    switch (item.tokenStatus) {
                        case 9:
                        case 2:
                            BlocksToast.get().showToast(R.string.this_coin_not_support_writh);
                            break;
                        case 1:
                        case 3:
                            itemListener.OnEextractCoinClick(item);

                    }

                }
            }
        });
        helper.getView(R.id.tv_enter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemListener != null) {
                    if (pos == 0) {
                        itemListener.OnWalletIntoClick(item);

                    } else {
                        // // 充值提现状态  9：不可以充值提现 1 ：可以充值 可以提现 2：仅可以充值 3：仅可以提现
                        switch (item.tokenStatus) {
                            case 9:
                            case 3:
                                BlocksToast.get().showToast(R.string.this_coin_not_support_recharge);
                                break;
                            case 1:
                            case 2:
                                itemListener.OnRechargeCoinClick(item);
                                break;
                        }
                    }
                }
            }
        });
    }


    private OnAssestItemListener itemListener;

    public void setOnItemListener(OnAssestItemListener itemListener) {
        this.itemListener = itemListener;
    }

    public interface OnAssestItemListener {

        void OnWalletIntoClick(WalletCurrencyBean bean);


        void OnRechargeCoinClick(WalletCurrencyBean bean);


        void OnEextractCoinClick(WalletCurrencyBean bean);
    }
}
